package pl.us.ij.plugins.segmentation.infrastructure;

import ij.ImagePlus;
import ij.process.FloatProcessor;

import java.util.LinkedList;
import java.util.List;

public class ColorConvertStrategy extends ConvertStrategy {

    private FloatProcessor floatProcessor;

    public ColorConvertStrategy(ImagePlus imp, CommandParams params) {
        super(imp, params);

        this.floatProcessor = null;

        List<Integer> channelMapList = new LinkedList<Integer>();

        if (params.isUseRed()) {
            channelMapList.add(0);
        }

        if (params.isUseGreen()) {
            channelMapList.add(1);
        }

        if (params.isUseBlue()) {
            channelMapList.add(2);
        }

        this.channelMap = channelMapList.toArray(this.channelMap);
    }

    public FloatProcessor getFloatProcessor(int channelNo) {

        return this.floatProcessor = this.inputImage.getProcessor().toFloat(this.channelMap[channelNo], this.floatProcessor);
    }
}

